package sctu.edu.java.year2016.team01.xuhanmei.day20160605.chapter12_1;

import javax.swing.*;
import java.awt.*;
import java.io.FileInputStream;


/**
 * Created by Administrator on 2016/6/5.
 * 实现读取文件时出现一个表示进度的进度条，可使用ProgressMonitorInputStream。。
 */
public class Example extends JFrame{
    public static void main(String[] args) throws Exception{
        JFrame jl=new JFrame("hhii");
        Container container =jl.getContentPane();
        jl.setSize(200,300);
        jl.setVisible(true);
        jl.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


        ProgressMonitorInputStream monitor;
        monitor=new ProgressMonitorInputStream(jl,"loading",new FileInputStream("D:/java小程序/from.txt"));
        ProgressMonitor p=monitor.getProgressMonitor();

        int read_unit=2;
        int all=monitor.available();
        int readed=0;
        byte[] data=new byte[read_unit];


        while(monitor.available()>0){
            Thread.sleep(1);
            int in=monitor.read();
            readed+=in;
            System.out.write(data);

            float progress=(float)readed/all*100;
           // System.out.println("archived"+progress+"%");
            p.setNote("ar"+progress+"%");
        }

    }
}
